// @ts-nocheck
import styles from "./index.module.less"
import { make } from "../../utils/dom"
import { isMobile } from "@/utils/index"
import ControlUploadDomBase from "../../lib/uploadDom/index"

const sucai_url = "/sucai?type=file"

class PDFParser {
	static get toolbox() {
		return {
			title: "PDFParser",
			icon: `<svg height="800px" width="800px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" 
          viewBox="0 0 309.539 309.539" xml:space="preserve">
       <g>
         <path style="fill:#E2574C;" d="M179.732,251.55c0-39.596,32.096-71.682,71.682-71.682c6.698,0,13.173,0.995,19.329,2.706V19.59
           h19.329V0.261h-19.329V0c0,0-156.827,0.193-212.573,0.251c-10.931,0-19.378,8.215-19.378,19.378v289.899h170.58
           C191.447,296.5,179.732,275.422,179.732,251.55z"/>
         <path style="fill:#B53629;" d="M290.074,0.271c-10.67,0-19.329,8.659-19.329,19.329v19.329h19.329
           c10.67,0,19.329-8.659,19.329-19.329C309.403,8.92,300.744,0.271,290.074,0.271z"/>
         <path style="fill:#3DB39E;" d="M251.415,193.563c32.028,0,57.988,25.959,57.988,57.988c0,32.009-25.959,57.988-57.988,57.988
           c-32.009,0-57.988-25.978-57.988-57.988C193.428,219.522,219.407,193.563,251.415,193.563z"/>
         <path style="fill:#FFFFFF;" d="M270.745,241.885h-9.665v-9.665c0-5.345-4.32-9.665-9.665-9.665s-9.665,4.32-9.665,9.665v9.665
           h-9.665c-5.345,0-9.665,4.32-9.665,9.665c0,5.345,4.32,9.665,9.665,9.665h9.665v9.665c0,5.345,4.32,9.665,9.665,9.665
           c5.345,0,9.665-4.32,9.665-9.665v-9.665h9.665c5.345,0,9.665-4.32,9.665-9.665S276.09,241.885,270.745,241.885z"/>
         <path style="fill:#B53629;" d="M182.439,270.879H19.465c-10.67,0-19.329,8.659-19.329,19.329s8.659,19.329,19.329,19.329h189.929
           C196.482,300.163,186.855,286.633,182.439,270.879z"/>
         <path style="fill:#FFFFFF;" d="M217.57,137.15c3.247,0,4.832-2.832,4.832-5.567c0-2.832-1.662-5.567-4.832-5.567h-18.44
           c-3.586,0-5.605,2.986-5.605,6.282v45.317c0,4.04,2.3,6.282,5.403,6.282s5.403-2.242,5.403-6.282v-12.438h11.153
           c3.47,0,5.19-2.832,5.19-5.644c0-2.754-1.72-5.489-5.19-5.489h-11.153V137.15C204.329,137.15,217.57,137.15,217.57,137.15z
            M155.243,126.017h-13.492c-3.663,0-6.263,2.513-6.263,6.243v45.395c0,4.629,3.74,6.079,6.437,6.079h14.139
           c16.758,0,27.824-11.027,27.824-28.047C183.88,137.701,173.48,126.017,155.243,126.017z M155.9,172.542h-8.234v-35.334h7.422
           c11.211,0,16.101,7.529,16.101,17.918C171.189,164.839,166.396,172.542,155.9,172.542z M106.466,126.017H93.1
           c-3.779,0-5.866,2.493-5.866,6.282v45.317c0,4.04,2.397,6.282,5.644,6.282s5.683-2.242,5.683-6.282v-13.221h8.36
           c10.341,0,18.875-7.326,18.875-19.107C125.795,133.758,117.561,126.017,106.466,126.017z M106.244,153.764h-7.683v-17.106h7.683
           c4.755,0,7.78,3.702,7.78,8.553C114.014,150.043,110.999,153.764,106.244,153.764z"/>
       </g>
       </svg>`,
		}
	}
	static get isReadOnlySupported() {
		return true
	}
	constructor({ data, api, config, readOnly }) {
		this.data = {
			url: data.url,
		}
		this.api = api
		this.readOnly = readOnly
		this.config = config || {}
		this.wrapper = undefined
	}
	render() {
		this.wrapper = make("div", styles["cx-custom-iframe"])

		if (this.data && this.data.url) {
			const isPhone = isMobile()
			if (!isPhone) {
				const iframe = make("iframe", styles.iframe, { src: this.data.url })
				this.wrapper.append(iframe)
			} else {
				const link = make("a", styles.pdfLink, { innerHTML: "打开PDF" })
				link.onclick = () => {
					const iframe = make("iframe", styles.iframe, { src: this.data.url })
					this.wrapper.append(iframe)
					link.remove()
				}
				this.wrapper.append(link)
			}
		} else {
			this.wrapper.style.backgroundColor = "#f0f0f0"
			const config = {
				placeholder: this.config.placeholder,
				renderButtonText: "渲染PDF",
			}
			const controlUploadDomBase = new ControlUploadDomBase(this.wrapper, this.api, config)
			controlUploadDomBase.render()
		}

		return this.wrapper
	}

	save(blockContent) {
		return this.data
	}
}
export default PDFParser

